<template>
     <div class="components-container">
         <div class="header-form">
            <div class="layui-inline">
                <label class="layui-form-label" >统计日期从</label>
                <el-date-picker v-date v-model="selectData.SbydateGreaterAndEquals" type="date" placeholder="选择日期范围" @change="btnSearch">
                </el-date-picker>到
                <el-date-picker v-date v-model="selectData.SbydateLessAndEquals" type="date" placeholder="选择日期范围" @change="btnSearch">
                </el-date-picker>
            </div>
            <el-button type="primary" :disabled="downloadLoading" @click="btnSearch" :loading="this.$store.state.isloading" >搜索</el-button>
            <el-button :disabled="this.$store.state.isloading || downloadLoading"  @click="btnRepeat">重置</el-button>
        </div>
        <div style="margin-top:10px;">
          <ul class="toolList"> 
            <!-- <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
              <el-button  type="primary" :disabled="$store.state.isloading" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
            </li> -->
            <li>
            <el-button type="primary" :disabled="this.$store.state.isloading"  @click="exportExcel" style="margin-left:20px;">导出Excel</el-button>
            </li>
          </ul>
        </div>
        <el-table
            border
            stripe
            @current-change="selectRow"
            :data="dataList"
            :span-method="arraySpanMethod"
            highlight-current-row
            style="width: 100%; margin-bottom: 10px;margin-top:10px;"
            fixed
            :height= "height"
            :max-height="height"
            class='fontsize'
            v-loading="this.$store.state.isloading" element-loading-text="拼命加载中"
            >
            <!-- 表头部分 -->
              <el-table-column
              :prop="item.ColumnKey"
              :label="item.ColumnName"
              :order="item.ColumnOrder"
              :align="item.ColumnAlign"
              :width="item.ColumnWidth" 
              :key="index"
              v-for="(item,index) in headList">   
              </el-table-column>
            </el-table>
        <!-- <dataTable :headList="headList" :dataList="dataList"  :span-method="arraySpanMethod" :isIndex="true" :hiddenColumn="false" :pageOrder="pageOrder" :hiddenPageOrder="false" :height="height" @pageChange="pageChange" @selectRow="selectRow"></dataTable> -->
   
        <printmodal ref="printPdf"></printmodal>
        <cemeteryData ref="simpleReg" :orderType="order" @refreshData="getData"></cemeteryData>
     </div>
</template>


<script>
import dataTable from "@/components/Table/DataTable";
import cemeteryData from "./tombsUseMain";

import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import printmodal from "@/components/Pdf/Print";
import { PRINT } from "@/components/Pdf/PDF.js";
const INFO = "详情";
const EXPORT = "导出";
const ADD = "新增";
export default {
  name: "iceuseSearch",
  mixins: [manage],
  data() {
    return {
      selectData: {
        SbydateGreaterAndEquals: new Date(),
        SbydateLessAndEquals: new Date(),
        CdhCodnameEqual: null,
        CdhdriverEqual: null
      },
      height: "620",
      downloadLoading: false,
      Manufactor: [],
      cdhTypes: [],
      drivers: [],
      // AlldataList: [],
      headeraa: "",
      showname: {
        ColumnKey: "rowtype",
        ColumnName: "",
        ColumnOrder: "",
        ColumnAlign: "center",
        ColumnWidth: null
      }
    };
  },
  methods: {
    //当前选中行
    selectRow(row, columnIndex) {
      console.log(columnIndex);
      this.currentRow = row;
      console.log("currentRow", this.currentRow);
      this.$emit("selectRow", row, "");
    },
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 1) {
        if (columnIndex === 1) {
          return [1, 2];
        } else if (columnIndex === 2) {
          return [0, 0];
        }
      }
    },
    exportExcel() {
      var startTime;
      var endTime;
      if (this.selectData.SbydateGreaterAndEquals) {
        startTime = this.selectData.SbydateGreaterAndEquals.toLocaleDateString();
      } else {
        startTime = "空";
      }
      if (this.selectData.SbydateLessAndEquals) {
        endTime = this.selectData.SbydateLessAndEquals.toLocaleDateString();
      } else {
        endTime = "空";
      }
      var header = "内勤补贴汇总表" + "(" + startTime + "--" + endTime + ")";
      if (this.dataList.length === 0) {
        this.$message.error("无导出数据！");
        return;
      }
      this.downloadLoading = true;
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        export_json_to_excel(this.headList, this.dataList, header);
        this.downloadLoading = false;
      });
    },
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case INFO:
          //   this.$refs.simpleReg.open(this.order, this.currentRow.TMMID);
          break;
        case EXPORT:
          this.$refs.printPdf.report(
            PRINT.PDFICEDISPATCHSEARCH,
            this.getDataC()
          );
          break;
        default:
      }
    },
    //获取所属厂家
    QueryVdr() {
      apiBase.DoService({}, apiBase.getApiAdress().Depot.QueryVdrByZC, res => {
        this.Manufactor = res.data.content.OutData;
      });
    },
    getDataC() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      let data = {
        PageIndex: -1,
        PageSize: 0,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      return data;
    },
    percentNum(num2, num1) {
      if (num2 != 0 && num1 != 0) {
        return Math.round(num2 / num1 * 10000) / 100.0 + "%"; //小数点后两位百分比
      } else return "0";
    },
    getData() {
      var p = new Promise((resolve, reject) => {
        let Data = JSON.parse(JSON.stringify(this.selectData));
        if (this.selectData.SbydateGreaterAndEquals) {
          Data.SbydateGreaterAndEquals = formatDate(
            Data.SbydateGreaterAndEquals,
            "yyyyMMdd"
          );
        }
        if (this.selectData.SbydateLessAndEquals) {
          Data.SbydateLessAndEquals = formatDate(
            Data.SbydateLessAndEquals,
            "yyyyMMdd"
          );
        }

        apiBase.DoService(
          Data,
          apiBase.getApiAdress().Report.QueryInternalSubsidySummary,
          res => {
            this.dataList = res.data.content;
            this.headeraa = this.percentNum(
              this.dataList[0].高档炉,
              this.dataList[0].火化数
            );
            resolve();
          }
        );
      });
      p.then(res => {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Column.GetInternalSubsidySummaryColumns,
          res => {
            this.headList = res.data.content;
            this.headList.unshift(this.showname);
            this.showname.ColumnName = this.headeraa;
          }
        );
      });
    },
    //获取派车类别
    getSendCdhTypes() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetSendCdhType,
        res => {
          let cdhTypeData = res.data.content,
            legendsCdhData = cdhTypeData.map(item => ({
              label: item.CodeName,
              value: item.CodeValue
            }));
          this.cdhTypes = legendsCdhData;
        }
      );
    },
    //获取司机
    getDrivers() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Staff.QueryDriver, res => {
        let driverData = res.data.content,
          legendsDrivers = driverData.map(item => ({
            label: item.STANAME,
            value: item.STAID
          }));
        this.drivers = legendsDrivers;
      });
    },

    btnShow(btn) {
      switch (btn) {
        case "导出":
          return true;
          break;
        case "详情":
          return true;
          break;
        default:
          return false;
      }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {
        SbydateGreaterAndEquals: new Date(),
        SbydateLessAndEquals: new Date(),
        CdhCodnameEqual: null,
        CdhdriverEqual: null
      };
      this.getData();
    }
  },
  mounted() {},
  components: {
    dataTable,
    cemeteryData,
    printmodal
  },
  created() {
    this.getData(); //获取数据
    this.QueryVdr();
    this.getSendCdhTypes();
    this.getDrivers();
  },
  activated() {
    this.getData(); //获取
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>

